import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'

//上一页
export const BACK_PAGE = () => {
  history.go(-1)
}

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    children:[
      {
        path: 'activeList',
        name: 'activeList',
        meta:{
          title:'活动列表',
          isShow:true
        },
        component: () => import(/* webpackChunkName: "activeList" */'../views/ActiveListView.vue')
      },
      {
        path:"mySubmit",
        name:'mySubmit',
        meta:{
          title:'我的提交',
          isShow:true
        },
        component: () => import(/* webpackChunkName: "mySubmit" */'../views/MysubmitView.vue')
      },
      // 其他路由...
      {
        path: '/active/:id',
        name: 'activeDetail',
        component:()=>import('../views/ActiveDetailView.vue'),
        meta: {
          title: '活动详情',
          isShow: false, // 如果不需要在侧边栏显示，设置为 false
        }
      },
    ]
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },

  {
    path: '/user/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },

]

// 设置路由守卫



const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 设置路由守卫
// router.beforeEach((to, from, next) => {
//   const isAuthenticated = localStorage.getItem('authentication'); // 检查本地存储中是否有登录凭证
//   if (to.name !== 'login' && !isAuthenticated) {
//     next({ name: 'login' });  // 未登录时强制跳转到登录页
//   } else {
//     next();  // 继续导航
//   }
// });


export default router
